﻿package DAO;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import model.Language;

public class LanguageDao {

	public LanguageDao() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	String url = "jdbc:mysql://localhost:3306/QUESTUDY";
	String user = "root";
	String pass = "webclass";

	//String pass = "webclass";


	
	// language 종류 불러오기 (어학성적 매길때)
	public ArrayList<Language> getAllLanguage() throws Exception {
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		ArrayList<Language> language = new ArrayList<Language>();
		try {
			
			con = DriverManager.getConnection(url, user, pass);
			pstmt = con.prepareStatement("select * from language");
			rs = pstmt.executeQuery();
			while (rs.next()) {
				
				int langid = rs.getInt("langid");
				String langName = rs.getString("langName").trim();
	
				language.add(new Language(langid, langName));
			}
			
			return language;

		} catch (Exception ex) {
			ex.printStackTrace();
			return language;
		} finally {
			if (rs != null)
				try {
					rs.close();
				} catch (SQLException ex) {
				}
			if (pstmt != null)
				try {
					pstmt.close();
				} catch (SQLException ex) {
				}
			if (con != null)
				try {
					con.close();
				} catch (SQLException ex) {
				}
		}
		

	}
	
}